#!/usr/bin/python3

import cv2

#img = cv2.imread('/Users/ben/Documents/AI/CSDN/pics/lena.jpg', 0)
img = cv2.imread('/Users/ben/Documents/AI/CSDN/pics/number.png', 0)
# cv2.imshow('GRAY Source:', img)

x = cv2.Sobel(img, cv2.CV_16S, 1, 0)#对x求导
y = cv2.Sobel(img, cv2.CV_16S, 0, 1)#对y求导


absX = cv2.convertScaleAbs(x)   # 转回uint8
absY = cv2.convertScaleAbs(y)

dst = cv2.addWeighted(absX, 0.5, absY, 0.5, 0)

cv2.imshow('absX', absX)
cv2.imshow('absY', absY)
cv2.imshow('Result', dst)

img = cv2.imread('/Users/ben/Documents/AI/CSDN/pics/number.png')
# cv2.imshow('Source:', img)

x = cv2.Sobel(img, cv2.CV_16S, 1, 0)  # 对x求导
y = cv2.Sobel(img, cv2.CV_16S, 0, 1)  # 对y求导

absX = cv2.convertScaleAbs(x)   # 转回uint8
absY = cv2.convertScaleAbs(y)

dst = cv2.addWeighted(absX, 0.5, absY, 0.5, 0)

cv2.imshow('Result-color:', dst)

cv2.waitKey()
cv2.destroyAllWindows()
